function inheritPrototype(Child, Parent) {
    var F = function () {};
    F.prototype = Parent.prototype;
    Child.prototype = new F();
    Child.prototype.constructor = Child;
}

/*
*
* public.js
* */

var wAlert = window.alert;
window.alert = function (message) {
    try {
        var iframe = document.createElement("IFRAME");
        iframe.style.display = "none";
        iframe.setAttribute("src", 'data:text/plain,');
        document.documentElement.appendChild(iframe);
        var alertFrame = window.frames[0];
        var iwindow = alertFrame.window;
        if (iwindow == undefined) {
            iwindow = alertFrame.contentWindow;
        }
        iwindow.alert(message);
        iframe.parentNode.removeChild(iframe);
    }
    catch (exc) {
        return wAlert(message);
    }
}
var wConfirm = window.confirm;
window.confirm = function (message) {
    try {
        var iframe = document.createElement("IFRAME");
        iframe.style.display = "none";
        iframe.setAttribute("src", 'data:text/plain,');
        document.documentElement.appendChild(iframe);
        var alertFrame = window.frames[0];
        var iwindow = alertFrame.window;
        if (iwindow == undefined) {
            iwindow = alertFrame.contentWindow;
        }
        var result = iwindow.confirm(message);
        if (result) {
            return true;
        } else {
            return false;
        }
        iframe.parentNode.removeChild(iframe);
    }
    catch (exc) {
        return wConfirm(message);
    }

}

/*
 *get screen width && height
 * */

function getWidth() {
    var xWidth = null;
    if (window.innerWidth !== null) {
        xWidth = window.innerWidth;
    } else {
        xWidth = document.body.clientWidth;
    }
    return xWidth*2;
}
//get screen height
function getHeight() {
    var xHeight = null;
    if (window.innerHeight !== null) {
        xHeight = window.innerHeight;
    } else {
        xHeight = document.body.clientHeight;
    }
    return xHeight*2;
}

/*
 * 判断放手后往那里滚
 * */
//var revenue = [350,450,550,650,850,1000,1100,1250,1500];
//var reward   = [0,30,40,50,100,200,240,300,400];
/*
 根据指定的值，在revenue查找第一个比它大的值，返回对应的索引，通过索引在reward获取对应的奖励
 1：如果值小于revenue最小的值时，则奖励0。所以reward前被了个0
 2：如果值大于revenue最大的值时，则奖励最高一档

 ***注意***
 前提是：revenue为整型数组，且已经按照从小到大排好了序的
 */
function find(array,val){
    //如果值小于revenue最小的值时，则奖励0
    if(val  <   Math.min.apply(null,array)){
        return 0;
    };
    //如果值大于revenue最大的值时，则奖励最高一档
    if(val  >   Math.max.apply(null,array)){
        return array.length-1;
    };
    var idx =   0,
        i   =   0,
        j   =   array.length;
    for(;i<j;i++){
        if(array[i] > val){
            idx = i;
            break;
        };
    };
    return idx;
};

/*
 * 获得随机颜色16进制
 * /*
 ** randomColorSixteen 产生任意长度随机字母数字组合
 ** randomFlag-是否任意长度 min-任意长度最小位[固定位数] max-任意长度最大位
 */

function randomColorSixteen (randomFlag, min, max){
    var str = "",
        range = min,
        arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];

    // 随机产生
    if(randomFlag){
        range = Math.round(Math.random() * (max-min)) + min;
    }
    for(var i=0; i<range; i++){
        pos = Math.round(Math.random() * (arr.length-1));
        str += arr[pos];
    }
    return "#"+str;
}
/**
 * HSL颜色值转换为RGB.
 * 换算公式改编自 http://en.wikipedia.org/wiki/HSL_color_space.
 * h, s, 和 l 设定在 [0, 1] 之间
 * 返回的 r, g, 和 b 在 [0, 255]之间
 *
 * @param   Number  h       色相
 * @param   Number  s       饱和度
 * @param   Number  l       亮度
 * @return  Array           RGB色值数值
 */
function hslToRgb(h, s, l){
    var r, g, b;

    if(s == 0){
        r = g = b = l; // achromatic
    }else{
        var hue2rgb = function hue2rgb(p, q, t){
            if(t < 0) t += 1;
            if(t > 1) t -= 1;
            if(t < 1/6) return p + (q - p) * 6 * t;
            if(t < 1/2) return q;
            if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
            return p;
        }

        var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
        var p = 2 * l - q;
        r = hue2rgb(p, q, h + 1/3);
        g = hue2rgb(p, q, h);
        b = hue2rgb(p, q, h - 1/3);
    }

    return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
}

/**
 * RGB 颜色值转换为 HSL.
 * 转换公式参考自 http://en.wikipedia.org/wiki/HSL_color_space.
 * r, g, 和 b 需要在 [0, 255] 范围内
 * 返回的 h, s, 和 l 在 [0, 1] 之间
 *
 * @param   Number  r       红色色值
 * @param   Number  g       绿色色值
 * @param   Number  b       蓝色色值
 * @return  Array           HSL各值数组
 */
function rgbToHsl(r, g, b){
    r /= 255, g /= 255, b /= 255;
    var max = Math.max(r, g, b), min = Math.min(r, g, b);
    var h, s, l = (max + min) / 2;

    if(max == min){
        h = s = 0; // achromatic
    }else{
        var d = max - min;
        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
        switch(max){
            case r: h = (g - b) / d + (g < b ? 6 : 0); break;
            case g: h = (b - r) / d + 2; break;
            case b: h = (r - g) / d + 4; break;
        }
        h /= 6;
    }

    return [h, s, l];
}
/*
* 16进制 to hsl
* */
function hexToHsl(sHex){
    var sRgbColor = sHex.colorRgb();
    var sHsl = rgbToHsl(sRgbColor[0],sRgbColor[1],sRgbColor[2]);
    return sHsl;
}

// by zhangxinxu welcome to visit my personal website http://www.zhangxinxu.com/
// 2010-03-12 v1.0.0
//十六进制颜色值域RGB格式颜色值之间的相互转换

//-------------------------------------
//十六进制颜色值的正则表达式
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
/*RGB颜色转换为16进制*/
String.prototype.colorHex = function(){
    var that = this;
    if(/^(rgb|RGB)/.test(that)){
        var aColor = that.replace(/(?:\(|\)|rgb|RGB)*/g,"").split(",");
        var strHex = "#";
        for(var i=0; i<aColor.length; i++){
            var hex = Number(aColor[i]).toString(16);
            if(hex === "0"){
                hex += hex;
            }
            strHex += hex;
        }
        if(strHex.length !== 7){
            strHex = that;
        }
        return strHex;
    }else if(reg.test(that)){
        var aNum = that.replace(/#/,"").split("");
        if(aNum.length === 6){
            return that;
        }else if(aNum.length === 3){
            var numHex = "#";
            for(var i=0; i<aNum.length; i+=1){
                numHex += (aNum[i]+aNum[i]);
            }
            return numHex;
        }
    }else{
        return that;
    }
};

//-------------------------------------------------

/*16进制颜色转为RGB格式*/
String.prototype.colorRgb = function(){
    var sColor = this.toLowerCase();
    if(sColor && reg.test(sColor)){
        if(sColor.length === 4){
            var sColorNew = "#";
            for(var i=1; i<4; i+=1){
                sColorNew += sColor.slice(i,i+1).concat(sColor.slice(i,i+1));
            }
            sColor = sColorNew;
        }
        //处理六位的颜色值
        var sColorChange = [];
        for(var i=1; i<7; i+=2){
            sColorChange.push(parseInt("0x"+sColor.slice(i,i+2)));
        }
        //return "RGB(" + sColorChange.join(",") + ")";
        return sColorChange;
    }else{
        return sColor;
    }
};
/*
* 设置浏览器地址栏url
* */
function setURL(url){

}


//var a = "#ffffff";
//console.log(hexToHsl(a))
/*
var sRgb = "RGB(23, 245, 56)" , sHex = "#34538b";
var sHexColor = sRgb.colorHex();
var sRgbColor = sHex.colorRgb();
console.log(rgbToHsl(sRgbColor[0],sRgbColor[1],sRgbColor[2]))*/

//判断手机横竖屏状态：
function hengshuping(evt){
    //console.log(evt)
    if(evt && !IS_INITIAL){
        //prepare();
        setTimeout(prepare,200)
        return;
        //console.log(evt)
    }
    var tmp;
    if(window.orientation==180||window.orientation==0){
        //alert("竖屏状态！")
        tmp = SCREEN_ORIENTION_V;

    }
    if(window.orientation==90||window.orientation==-90){
        //alert("横屏状态！")
        tmp = SCREEN_ORIENTION_H;
    }
    //console.log(window.screen.orientation.angle)
    try
    {
        if(window.screen.orientation.angle==180 || window.screen.orientation.angle==0){
            //alert("竖屏状态！")
            tmp = SCREEN_ORIENTION_V;

        }
        if(window.screen.orientation.angle==90 || window.screen.orientation.angle==-90){
            //alert("横屏状态！")
            tmp = SCREEN_ORIENTION_H;
        }
    }catch (e){

    }



    var ori_alert_obj = document.getElementById("oriention_mask");
    if(tmp != MY_SCREEN_ORIENTION){

        ori_alert_obj.style.visibility="visible";
        if(MY_SCREEN_ORIENTION == SCREEN_ORIENTION_V){
            console.log("请竖屏");
            ori_alert_obj.innerHTML="请竖屏观看";

        }else{
            console.log("请横屏");
            ori_alert_obj.innerHTML="请横屏观看";
        }
    }else{
        ori_alert_obj.style.visibility="hidden";
    }

    return tmp;





}

//javascript判断是否是微信访问
function is_weixin(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}
//javascript获取版本号
function weixin_version()
{
    var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i) ;
    return wechatInfo[1];
    //if( !wechatInfo ) {
    //    alert("本活动仅支持微信") ;
    //} else if ( wechatInfo[1] < "5.0" ) {
    //    alert("本活动仅支持微信5.0以上版本") ;
    //}
}
//获取url中的参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", hengshuping, false);


//判断当前浏览器
var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
var browser_phone = ''
if (ua.match(/MicroMessenger/i) == "micromessenger") {
    browser_phone = 'wx';
}
else if (ua.match(/WeiBo/i) == "weibo") {
    browser_phone = 'wb';
}
else if (ua.match(/QQ/i) == "qq") {
    browser_phone = 'qq';
}
//debug
//browser='wx';
//微信自定义分享变量
var SHARE_CONFIG={};
var MAIN_PAGE_PATH = window.location.protocol+"//"+window.location.host+VIRTURL_PATH;
//判断是否需要实现微信 自定义分享
if(browser_phone == 'wx') {
    var apiUrl = 'http://wx.eoiyun.com/Home/WxIndex/wxConfig2';
    var formData = {appid:''};
    $.ajax({
        type:"post",
        url:apiUrl,
        dataType:"json",
        data:formData,
        processData : false,
        contentType : false,
        success:function(data){
            SHARE_CONFIG = data;
            SHARE_CONFIG.title = '测试分享标题';
            SHARE_CONFIG.desc = '测试分享正文';
            SHARE_CONFIG.img = MAIN_PAGE_PATH+'share_icon.png';
            //$('#custom_share_div').load(MAIN_PAGE_PATH+'eosi/website/Assembly/html/wx_custom_share.html');
        },
        error:function(e){

        }
    });
    document.write("<script src='./libs/jweixin-1.2.0.min.js?v="+version+"'><\/script>");
    document.write("<script src='./eosi/website/Assembly/html/wx_custom_share.js?v="+version+"'><\/script>");

}

//是否是手机
var ISMOBILE = false;
//是否是IOS
var ISIOS = false;
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    ISMOBILE = true;
    if( /iPhone|iPad|iPod/i.test(navigator.userAgent) ) {
        ISIOS = true;
    }
}